package cn.softcits.thread.even;

import java.util.concurrent.ExecutionException;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-07-04 3:20 PM
 */
public class PrintOdd extends Thread {

    private Count count;
    public PrintOdd(String name, Count count) {
        this.setName(name);
        this.count = count;
    }
    @Override
    public  void run() {
        synchronized (count) {
        while(true) {
            try {
                Thread.sleep(1000);

                if(count.getNum() % 2 == 0) {
                    count.wait();
                } else {
                    System.out.println(Thread.currentThread().getName() + " : " + count.getNum());
                    count.setNum(count.getNum() + 1);
                    count.notify();
                }

            } catch (Exception e) {

            }
        }

        }
    }
}
